#include "TimerDriver.h"



Flow_TimerDrv SysTickTimer = {
															 .Init = SysTickTimerInit,
															 .TimIntCallBack = SysTickTimerCallBack
														 };

														 
														 
static void SysTickTimerInit(uint32_t TimBase)
{
	TIMER_BaseInitPara TIM_TimeBaseStructure;
	NVIC_InitPara NVIC_InitStructure;
	TIM_TimeBaseStructure.TIMER_Prescaler     = 1080-1;
	TIM_TimeBaseStructure.TIMER_Period        = 100-1;
	TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV2;
	TIM_TimeBaseStructure.TIMER_CounterMode   = TIMER_COUNTER_UP; 
	
	RCC_APB1PeriphClock_Enable(RCC_APB1PERIPH_TIMER2, ENABLE);
	TIMER_BaseInit(TIMER2,&TIM_TimeBaseStructure);
	TIMER_Enable(TIMER2, ENABLE);
	TIMER_INTConfig(TIMER2 ,TIMER_INT_UPDATE,ENABLE);
	
	NVIC_InitStructure.NVIC_IRQ = TIMER2_IRQn;
	NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
	NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;
	NVIC_InitStructure.NVIC_IRQSubPriority = 1;
	NVIC_Init(&NVIC_InitStructure);
}




static void SysTickTimerCallBack(void)
{	
	if(FREQDrv.Read() == FLOW_SET)
	{
		FREQDrv.Write(FLOW_RESET);
	}
	else
	{
		FREQDrv.Write(FLOW_SET);
	}
	
	OSSchedule.RealSchdeule();
	OSTickSystem.Update();
	
}



